import { axios } from '@/utils/request'
import store from '@/store'
import storage from 'store'
import { ACCESS_TOKEN } from '@/store/mutation-types'

const publicConfig = store.getters.publicConfig

const api = {
  list: '/student.index/list',
  edit: '/student.index/edit',
  delete: '/student.index/delete',
  exportAvatar: '/student.index/exportAvatar'
}

/**
 * 学员列表
 */
export function list(params) {
  return axios({
    url: api.list,
    method: 'get',
    params
  })
}

/**
 * 编辑记录
 * @param {*} data
 */
export function edit(data) {
  return axios({
    url: api.edit,
    method: 'post',
    data
  })
}

/**
 * 删除记录
 * @param {*} data
 */
export function deleted(data) {
  return axios({
    url: api.delete,
    method: 'post',
    data: data
  })
}

/**
 * 导出学员
 */
export function exportExcel(params) {
  const token = storage.get(ACCESS_TOKEN)
  params['Access-Token'] = token
  var newParams = []
  for (const k in params) {
    if (params[k] != undefined) {
      newParams.push(`${k}=${params[k]}`)
    }
  }
  console.log(publicConfig.BASE_API + api.list + '&' + newParams.join('&'))
  window.location.href = publicConfig.BASE_API + api.list + '&' + newParams.join('&')
}

/**
 * 导出头像
 */
export function exportAvatar(data) {
  return axios({
    url: api.exportAvatar,
    method: 'post',
    data: data
  })
}
